package com.demo.dao.impl;

import com.demo.dao.AccountDao;
import com.demo.mapper.AccountMapper;
import com.demo.pojo.Account;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @ClassName a
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/1 11:57
 * @Version 1.0
 **/
public class AccountDaoImpl implements AccountDao {

    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public Account findAccountById(Integer accountId) {
        List<Account> accounts = jdbcTemplate.query("select * from account where id=?", new AccountMapper(), accountId);
        return accounts.get(0);
    }

    public Account findAccountByName(String accountName) {
            List<Account> accounts = jdbcTemplate.query("select * from account where name=?", new AccountMapper(), accountName);
        return accounts.get(0);
    }

    public void updateAccount(Account account) {
        jdbcTemplate.update("update account set name=?,money=? where id=?", account.getName(), account.getMoney(), account.getId());
    }
}

